import { useEffect } from "react";
import { AppState, AppStateStatus } from "react-native";

type OnBackground = () => {}

const useBackgroundEffect = (onBackground: OnBackground) => {
  useEffect(() => {
    const handleAppStateChange = (nextAppState: AppStateStatus) => {
      if (nextAppState === "background") {
        onBackground();
      }
    };
    AppState.addEventListener("change", handleAppStateChange);
  }, [onBackground]);
};

export default useBackgroundEffect;
